using System;
using SharpWind.Resources.Creators;
using SharpWind.Tools;

namespace SharpWind.Resources.Managers
{
	public class ShaderManager : ResourceManager<Shader> 
	{
		internal ShaderManager() : base()
		{
			
		}

		public Shader Load( string name )
		{
			ShaderFromFileCreator creator = new ShaderFromFileCreator( Directories.Shaders + name );
			return this.Create( name, creator );
		} // Load(name)

		protected override void OnDeviceLost( object sender, EventArgs e )
		{
			foreach( InternalResource<Shader> resource in this.resources.Values )
			{
				if( !resource.Resource.D3DEffect.Disposed && 
					resource.Resource.D3DEffect != null )
				{
					resource.Resource.D3DEffect.OnLostDevice();
				}
			}
		}

		protected override void OnDeviceReset( object sender, EventArgs e )
		{
			foreach( InternalResource<Shader> resource in this.resources.Values )
			{
				if( !resource.Resource.D3DEffect.Disposed &&
					resource.Resource.D3DEffect != null )
				{
					resource.Resource.D3DEffect.OnResetDevice();
				}
			}
		}

		public override Shader this[string name]
		{
			get
			{
				return Load( name );
			}
		}
	}
}
